package cn.yuhh.core.type;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-02-17 15:50
 * @descreption
 **/
public enum  DeclareStatus {

    accepted(0,"待受理","accept:1.0","受理:不受理")
    //受理和不受理都要通知申报人
    ,division(1,"待分配","distribution:1.0","分配:打回"),

    //办理合不合格都要走拟审批到审批领导
    handle(2,"办理中","handlerService:1.0","通过:不通过"),
    //办理不合格也可以打给经办人
    distExamine(3,"拟审核","distApproval:1.0","通过:不通过"),

    //不通过经办人
    examine(4,"待审批","checkService:1.0","通过:不通过"), ISSUE(5,"待签发","issue:1.0","签发:不通过"),ISSUEED(6,"已签发","end:1.0","归档:不通过")

    ,end(7,"已办结","",""),

    //受理到分供方领导   对应下一步是不受理
    callBack(11,"打回","declare:1.0","提交:"),unqualified(12,"不合格","distApproval:1.0","分配:"),

    //受理员到申报人
    unaccepted(13,"不受理","declare:1.0","提交:");

    public static Map<Integer,DeclareStatus> map = new HashMap(){{
        put(0, accepted);
        put(1, division);
        put(2, handle);
        put(3, distExamine);
        put(4, examine);
        put(5, ISSUE);
        put(6, ISSUEED);
        put(7, end);

        put(11, callBack);
        put(12, unqualified);
        put(13, unaccepted);
    }};

    DeclareStatus(int index,String name,String nextService,String menu) {
        this.index = index;
        this.name = name;
        this.nextService = nextService;
        this.menu = menu;
    }

    private String nextService;

    private Integer index;

    private String name;

    private String menu;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getMenu() {
        return menu;
    }

    public void setMenu(String menu) {
        this.menu = menu;
    }

    public DeclareStatus handler(Whether whether){
        return handler(whether, 1);
    }

    public DeclareStatus handler(Whether whether,int step){
        if(Whether.N.equals(whether)){
            return pre(step);
        }else {
            return next(step);
        }
    }

    public DeclareStatus next(int step){
        if(index.equals(11)||index.equals(13)){
            return division;
        }
        if(this.index.equals(12) ){
            return examine;
        }
        if(index.equals(7)){
            return end;
        }
        return map.get(this.index + step);
    }

    private DeclareStatus pre(int step){
        if(this.index ==0 ){
            return unaccepted;
        }

        if(index.equals(11)||index.equals(13)){
            return division;
        }

        if(this.index.equals(12) ){
            return examine;
        }

        return map.get(this.index - step);
    }

    public String getNextService() {
        return nextService;
    }

    public void setNextService(String nextService) {
        this.nextService = nextService;
    }

}